package lab_2_server;

import java.io.File;
import java.util.GregorianCalendar;

/**
 * My Lggger for output to file or console
 * @author pacific
 */
public class MyLogger {
    
    /** Write message to selected output Chanel */
    public static void putMessange( Exception ex ) {
        putMessange( ex.toString(), getTypeOfLog() ) ;
    }


    /** Write message to selected output Chanel */
    public static void putMessange( String msg ) {
        putMessange(msg, getTypeOfLog()) ;
    }

    /**
     * Write message to selected output Chanel
     * @param msg - message to output
     * @param typeLog - type of output
     */
    public static void putMessange( String msg, int typeLog ) {
        switch (typeLog) {
            case LOG_TO_FILE:
                break;
            case LOG_TO_CONSOLE:
                System.out.println(getPrettyTime() + " " + msg);
                System.out.flush();
                break;
        }
    }


    /** Get String in pretty view */
    private static  String getPrettyTime() {
        GregorianCalendar calendar = new GregorianCalendar();
        int year, month, day, hours, minutes, seconds;
        year = calendar.get(GregorianCalendar.YEAR);
        month = calendar.get(GregorianCalendar.MONTH) + 1;
        day = calendar.get(GregorianCalendar.DAY_OF_MONTH);
        hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);
        minutes = calendar.get(GregorianCalendar.MINUTE);
        seconds = calendar.get(GregorianCalendar.SECOND);
        return hours+":"+minutes+":"+seconds+"^"+day+"."+month+"."+year ;
    }


    //-----Fields-----

    public static final int LOG_TO_FILE = 1 ;
    public static final int LOG_TO_CONSOLE = 2 ;
    
    private static File fileForLog = new File( "Logs.txt" ) ;
    private static int typeOfLog = LOG_TO_CONSOLE ;

    

    //-----Getters and Setters
    
    private static int getTypeOfLog() {
        return typeOfLog;
    }

    private static File getFileForLog() {
        return fileForLog;
    }
}
